package com.erpanderp.wam.ac.view.project;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.erpanderp.wam.ac.model.entity.project.ProjectAssignment;
import com.erpanderp.wam.ac.model.entity.project.ProjectAssignmentDetail;
import com.erpanderp.wam.ac.model.service.project.ProjectAssignmentDAO;
import com.erpanderp.wam.tm.model.service.RRFDAO;
import com.erpanderp.wam.usm.model.entity.projectandassignment.Project;
import com.erpanderp.wam.usm.model.entity.user.Employee;
import com.erpanderp.wam.usm.model.entity.user.EmployeeAndReporting;
import com.erpanderp.wam.usm.model.entity.user.NewJoinee;
import com.erpanderp.wam.usm.model.entity.user.PassportAndPANDetails;
import com.erpanderp.wam.usm.model.entity.user.WAMUser;
import com.erpanderp.wam.usm.model.service.projectandassignment.ProjectDAO;
import com.erpanderp.wam.util.CommonLookup;
import com.erpanderp.wam.util.EmailUtil;
@ManagedBean
@ViewScoped
public class CreatIinternationalProjectAssignmentBean implements Serializable {
private static final long serialVersionUID = 1L;

HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
ServletContext context = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();

ProjectDAO projectDAO = new ProjectDAO();
ProjectAssignmentDAO projectAssignmentDAO = new ProjectAssignmentDAO();
RRFDAO rrfDAO = new RRFDAO();

private boolean FORM_VALID;

private ProjectAssignment projectAssignment = new ProjectAssignment();
private ProjectAssignmentDetail projectAssignmentDetail = new ProjectAssignmentDetail();
private Employee employee = new Employee();
private NewJoinee newJoinee = new NewJoinee();
private PassportAndPANDetails passportAndPANDetails = new PassportAndPANDetails();
private EmployeeAndReporting employeeAndReporting = new EmployeeAndReporting();


private List<Project> projects = new ArrayList<Project>();
private List<PassportAndPANDetails> passportAndPANDetailsList = new ArrayList<PassportAndPANDetails>();
private Map<String, Long> projectsMap = new HashMap<String, Long>();

private Long selectedProjectId;
private Project selectedProject= new Project();

private WAMUser wamUser = new WAMUser();
private String InternationalProjectAssignmentCode;
private String employeeId;
private String passportNumber;
private String contactNumber="";
private String approvedBy="";
private Float advanceAmount;
private Float roomRentAdvance;
private Date createDate;
private String additionals;
String EMAIL_MESSAGE;

private Employee reportingManager = new Employee();
private Long reportingManagerId;
private EmailUtil emailUtil = new EmailUtil();

public CreatIinternationalProjectAssignmentBean()
{
	setWamUser((WAMUser) session.getAttribute(CommonLookup.SESSION_ATTRIBUTE_WAMUSER));
	InternationalProjectAssignmentCode=CommonLookup.getAutoGeneratedInternationalProjectAssignmentCode(wamUser.getEmployee().getEmployeeCode());
	System.out.println("InternationalProjectAssignmentId.........."+InternationalProjectAssignmentCode);
	setCreateDate(new Date());
	employee.setFirstName(wamUser.getEmployee().getFirstName());
	employee.setLastName(wamUser.getEmployee().getLastName());
	setEmployeeId(wamUser.getEmployee().getEmployeeCode());
	wamUser.getEmployee().getNewJoinee().getPassportAndPANDetails();
	//miscExpensesDetails.addAll(miscExpense.getMiscExpensesDetails());
	passportAndPANDetailsList.addAll(wamUser.getEmployee().getNewJoinee().getPassportAndPANDetails());
	for(PassportAndPANDetails passportAndPANDetails : passportAndPANDetailsList){
		setPassportNumber(passportAndPANDetails.getPassportNumber());
	}
	
	setContactNumber(wamUser.getEmployee().getTelephone());
	setApprovedBy(CommonLookup.PROJECTASSIGNMENT_DOMESTIC_INTERNATIONAL_APPROVER);
	
	
	reportingManager = rrfDAO.getReportingManager(wamUser.getEmployee().getEmployeeId());
	System.out.println("reportingManager.........."+reportingManager);
	setReportingManagerId(reportingManager.getEmployeeId());
	  
}


//GETTERS AND SETTERS
public HttpSession getSession() {
	return session;
}
public void setSession(HttpSession session) {
	this.session = session;
}
public HttpServletRequest getRequest() {
	return request;
}
public void setRequest(HttpServletRequest request) {
	this.request = request;
}
public ServletContext getContext() {
	return context;
}
public void setContext(ServletContext context) {
	this.context = context;
}
public ProjectDAO getProjectDAO() {
	return projectDAO;
}
public void setProjectDAO(ProjectDAO projectDAO) {
	this.projectDAO = projectDAO;
}
public ProjectAssignmentDAO getProjectAssignmentDAO() {
	return projectAssignmentDAO;
}
public void setProjectAssignmentDAO(ProjectAssignmentDAO projectAssignmentDAO) {
	this.projectAssignmentDAO = projectAssignmentDAO;
}
public RRFDAO getRrfDAO() {
	return rrfDAO;
}
public void setRrfDAO(RRFDAO rrfDAO) {
	this.rrfDAO = rrfDAO;
}
public boolean isFORM_VALID() {
	return FORM_VALID;
}
public void setFORM_VALID(boolean fORM_VALID) {
	FORM_VALID = fORM_VALID;
}
public ProjectAssignment getProjectAssignment() {
	return projectAssignment;
}
public void setProjectAssignment(ProjectAssignment projectAssignment) {
	this.projectAssignment = projectAssignment;
}
public ProjectAssignmentDetail getProjectAssignmentDetail() {
	return projectAssignmentDetail;
}
public void setProjectAssignmentDetail(
		ProjectAssignmentDetail projectAssignmentDetail) {
	this.projectAssignmentDetail = projectAssignmentDetail;
}
public Employee getEmployee() {
	return employee;
}
public void setEmployee(Employee employee) {
	this.employee = employee;
}
public EmployeeAndReporting getEmployeeAndReporting() {
	return employeeAndReporting;
}
public void setEmployeeAndReporting(EmployeeAndReporting employeeAndReporting) {
	this.employeeAndReporting = employeeAndReporting;
}
public List<Project> getProjects() {
	return projects;
}
public void setProjects(List<Project> projects) {
	this.projects = projects;
}
public Map<String, Long> getProjectsMap() {
	return projectsMap;
}
public void setProjectsMap(Map<String, Long> projectsMap) {
	this.projectsMap = projectsMap;
}
public Long getSelectedProjectId() {
	return selectedProjectId;
}
public void setSelectedProjectId(Long selectedProjectId) {
	this.selectedProjectId = selectedProjectId;
}
public Project getSelectedProject() {
	return selectedProject;
}
public void setSelectedProject(Project selectedProject) {
	this.selectedProject = selectedProject;
}
public WAMUser getWamUser() {
	return wamUser;
}
public void setWamUser(WAMUser wamUser) {
	this.wamUser = wamUser;
}

public String getEmployeeId() {
	return employeeId;
}
public void setEmployeeId(String employeeId) {
	this.employeeId = employeeId;
}
public String getContactNumber() {
	return contactNumber;
}
public void setContactNumber(String contactNumber) {
	this.contactNumber = contactNumber;
}
public String getApprovedBy() {
	return approvedBy;
}
public void setApprovedBy(String approvedBy) {
	this.approvedBy = approvedBy;
}
public Float getAdvanceAmount() {
	return advanceAmount;
}
public void setAdvanceAmount(Float advanceAmount) {
	this.advanceAmount = advanceAmount;
}
public Float getRoomRentAdvance() {
	return roomRentAdvance;
}
public void setRoomRentAdvance(Float roomRentAdvance) {
	this.roomRentAdvance = roomRentAdvance;
}
public Date getCreateDate() {
	return createDate;
}
public void setCreateDate(Date createDate) {
	this.createDate = createDate;
}
public String getAdditionals() {
	return additionals;
}
public void setAdditionals(String additionals) {
	this.additionals = additionals;
}
public String getEMAIL_MESSAGE() {
	return EMAIL_MESSAGE;
}
public void setEMAIL_MESSAGE(String eMAIL_MESSAGE) {
	EMAIL_MESSAGE = eMAIL_MESSAGE;
}
public Employee getReportingManager() {
	return reportingManager;
}
public void setReportingManager(Employee reportingManager) {
	this.reportingManager = reportingManager;
}
public Long getReportingManagerId() {
	return reportingManagerId;
}
public void setReportingManagerId(Long reportingManagerId) {
	this.reportingManagerId = reportingManagerId;
}
public EmailUtil getEmailUtil() {
	return emailUtil;
}
public void setEmailUtil(EmailUtil emailUtil) {
	this.emailUtil = emailUtil;
}
public static long getSerialversionuid() {
	return serialVersionUID;
}


public String getInternationalProjectAssignmentCode() {
	return InternationalProjectAssignmentCode;
}


public void setInternationalProjectAssignmentCode(
		String internationalProjectAssignmentCode) {
	InternationalProjectAssignmentCode = internationalProjectAssignmentCode;
}


public String getPassportNumber() {
	return passportNumber;
}


public void setPassportNumber(String passportNumber) {
	this.passportNumber = passportNumber;
}
public PassportAndPANDetails getPassportAndPANDetails() {
	return passportAndPANDetails;
}


public void setPassportAndPANDetails(PassportAndPANDetails passportAndPANDetails) {
	this.passportAndPANDetails = passportAndPANDetails;
}


public NewJoinee getNewJoinee() {
	return newJoinee;
}


public void setNewJoinee(NewJoinee newJoinee) {
	this.newJoinee = newJoinee;
}


public List<PassportAndPANDetails> getPassportAndPANDetailsList() {
	return passportAndPANDetailsList;
}


public void setPassportAndPANDetailsList(List<PassportAndPANDetails> passportAndPANDetailsList) {
	this.passportAndPANDetailsList = passportAndPANDetailsList;
}

}
